#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <setjmp.h>
#include <time.h>
#include <sys/stat.h>

#include "progress_bar.h"

#define UNUSED(x) (void)x

static jmp_buf buf;
static void deal_ctrl_c(int sig);

int main(int argc, char* argv[])
{
    int ret = 0;
    struct progress_bar progress_data;

    system("stty -echo");
    
    signal(SIGINT, deal_ctrl_c);
    UNUSED(argc);
    UNUSED(argv);

    progress_bar_init(&progress_data);
    get_terminal_param(argc, argv, &progress_data);

    ret = setjmp(buf);
    if(ret != 1){
    	progress_bar_run(progress_data);
    }

    system("stty echo");
    return 0;
}

static void deal_ctrl_c(int sig)
{   
    system("clear");
    longjmp(buf, 1);
}